Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
12 lines (10 loc) · 675 Bytes

2.6.8 - onPacket.md

File metadata and controls

12 lines (10 loc) · 675 Bytes

onPacket

接收到UDP数据包时回调此函数,发生在worker进程中。函数原型:

function onPacket(Swoole\Server $server, string $data, array $client_info);
  • $server,Server对象
  • $data,收到的数据内容,可能是文本或者二进制内容
  • $client_info,客户端信息包括address/port/server_socket等多项客户端信息数据

服务器同时监听TCP/UDP端口时,收到TCP协议的数据会回调onReceive,收到UDP数据包回调onPacket。 服务器设置的EOFLength等自动协议处理,对UDP端口是无效的,因为UDP包本身存在消息边界,不需要额外的协议处理。